package net.sxnic.workflow.whimpl;

import java.util.List;

import net.sxnic.ugr.context.AppContext;
import net.sxnic.ugr.user.User;
import net.sxnic.ugr.utils.UgrManagerUtils;
import net.sxnic.workflow.context.WfContextImpl;
import net.sxnic.workflow.handler.AbstractHandler;
import net.sxnic.workflow.handler.HandlerExt;
import net.sxnic.workflow.handler.WfHandlerException;
import net.sxnic.workflow.wfentity.WfEntity;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;

public class SignPwdValidateHandler extends AbstractHandler<WfEntity> implements
		HandlerExt<WfEntity> {

	public SignPwdValidateHandler(WfContextImpl<WfEntity> context) {
		super(context);
	}

	@Override
	public void editExecute() throws WfHandlerException {

	}

	@Override
	public void saveExecute() throws WfHandlerException {

	}

	@Override
	public void viewExecute() throws WfHandlerException {

	}

	@Override
	public void submitExecute() throws WfHandlerException {
		
	}
	
	private boolean verifySignPwd(String username, String signPwd) {

		if (StringUtils.isBlank(username) || StringUtils.isBlank(signPwd)) {
			return false;
		}

		List<User> users = UgrManagerUtils.getUserManager().findBy("username", username);

		if (users == null || users.size() == 0) {
			return false;
		}

		if (DigestUtils.md5Hex(signPwd.trim())
				.equals(users.get(0).getSignPwd())) {
			return true;
		} else {
			return false;
		}
	}

}
